# -*- coding:utf-8 -*-
from django.dispatch import Signal

# module模块相关的信号，以下为定义声明信号,
#    利用接口Signal注册，其中参数为：
#    providing_args：信号提供给监听者的参数名列表
#    use_caching：


# 一旦module class被定义和注册到django module system中时，就发送该信号
# model类准备好
class_prepared = Signal(providing_args=["class"])

# 实例化一个django model时，在该model的__init__方法中，发送该信号
pre_init = Signal(providing_args=["instance", "args", "kwargs"], use_caching=True)          # 开始实例化一个django model
# __init__()方法结束
post_init = Signal(providing_args=["instance"], use_caching=True)                           # 实例化完成一个django model

# 执行models的save()方法的开始
pre_save = Signal(providing_args=["instance", "raw", "using", "update_fields"], use_caching=True)
# 执行models的save()方法的结束
post_save = Signal(providing_args=["instance", "raw", "created", "using", "update_fields"], use_caching=True)

# models的delete方法、Queryset的delete方法执行的开始
pre_delete = Signal(providing_args=["instance", "using"], use_caching=True)
post_delete = Signal(providing_args=["instance", "using"], use_caching=True)

# 该信号是否是python manage.py syncdb命令相关的信号呢?????????????????????????
pre_syncdb = Signal(providing_args=["app", "create_models", "verbosity", "interactive", "db"])
post_syncdb = Signal(providing_args=["class", "app", "created_models", "verbosity", "interactive", "db"])
# post_syncdb是在应用程序安装后由syncdb命令或flush命令触发的。
# django-admin.py flush命令用于将数据库还原为初次运行syncdb命令后的状态

# 当在一个model实例中有ManyToManyField发生变化时，发送该信号
m2m_changed = Signal(providing_args=["action", "instance", "reverse", "model", "pk_set", "using"], use_caching=True)
